/*
 * ViewPropertyForm.java
 *
 * Created on __DATE__, __TIME__
 */

package edu.washburn.cm333.project.gui;

import java.util.List;

import javax.persistence.EntityManager;

import edu.washburn.cm333.project.entities.Property;
import edu.washburn.cm333.project.entities.PropertyManager;

/**
 *
 * @author  __USER__
 */
public class ViewPropertyForm extends javax.swing.JFrame {

	/** Creates new form ViewPropertyForm */
	public ViewPropertyForm() {
		initComponents();
	}

	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		lblSelectProperty = new javax.swing.JLabel();
		EntityManager em = PropertyManager.getEntityManager();
		List<Property> propertyList = em.createQuery(
				"select t from Property t", Property.class).getResultList();
		cboxSelectProperty = new Java2sAutoComboBox(propertyList);
		lblAddress = new javax.swing.JLabel();
		lblCity = new javax.swing.JLabel();
		lblState = new javax.swing.JLabel();
		lblZip = new javax.swing.JLabel();
		lblDispAddress = new javax.swing.JLabel();
		jLabel6 = new javax.swing.JLabel();
		lblDispState = new javax.swing.JLabel();
		lblDispZip = new javax.swing.JLabel();
		btnExit = new javax.swing.JButton();

		setTitle("View Property");

		lblSelectProperty.setText("Select Property");
		lblSelectProperty.setToolTipText("");

		cboxSelectProperty.setSelectedIndex(-1);
		cboxSelectProperty
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						cboxSelectPropertyActionPerformed(evt);
					}
				});

		lblAddress.setText("Address");

		lblCity.setText("City");

		lblState.setText("State");

		lblZip.setText("Zip");

		jLabel6.setToolTipText("");

		lblDispState.setToolTipText("");

		btnExit.setText("Exit");
		btnExit.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnExitActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGap(69, 69, 69)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(lblSelectProperty)
												.addComponent(lblAddress)
												.addComponent(lblCity)
												.addComponent(lblState)
												.addComponent(lblZip))
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																		92,
																		Short.MAX_VALUE)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.TRAILING)
																				.addComponent(
																						lblDispAddress)
																				.addComponent(
																						cboxSelectProperty,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addComponent(
																						jLabel6)
																				.addComponent(
																						lblDispState)
																				.addComponent(
																						lblDispZip))
																.addGap(130,
																		130,
																		130))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		btnExit,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		68,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addContainerGap(
																		184,
																		Short.MAX_VALUE)))));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGap(38, 38, 38)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(lblSelectProperty)
												.addComponent(
														cboxSelectProperty,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(32, 32, 32)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(lblAddress)
												.addComponent(lblDispAddress))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(lblCity)
												.addComponent(jLabel6))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(lblState)
												.addComponent(lblDispState))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(lblZip)
												.addComponent(lblDispZip))
								.addGap(43, 43, 43).addComponent(btnExit)
								.addContainerGap(37, Short.MAX_VALUE)));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	private void cboxSelectPropertyActionPerformed(
			java.awt.event.ActionEvent evt) {
		Object a = ((Java2sAutoComboBox) cboxSelectProperty).autoTextFieldEditor
				.getItem();
		if (a instanceof Property) {
			lblDispAddress.setText(((Property) a).getStreetAddress());
			lblDispState.setText(((Property) a).getState());
			lblDispZip.setText(((Property) a).getZip());
			jLabel6.setText(((Property) a).getCity());
		}
	}

	private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {
		this.setVisible(false);
	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new ViewPropertyForm().setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton btnExit;
	private javax.swing.JComboBox cboxSelectProperty;
	private javax.swing.JLabel jLabel6;
	private javax.swing.JLabel lblAddress;
	private javax.swing.JLabel lblCity;
	private javax.swing.JLabel lblDispAddress;
	private javax.swing.JLabel lblDispState;
	private javax.swing.JLabel lblDispZip;
	private javax.swing.JLabel lblSelectProperty;
	private javax.swing.JLabel lblState;
	private javax.swing.JLabel lblZip;
	// End of variables declaration//GEN-END:variables

}